//
//  BS_TopWindow.swift
//  SWIFT_BAISI
//
//  Created by youxin on 2018/1/19.
//  Copyright © 2018年 YST. All rights reserved.
//

import UIKit


    class BS_TopWindow: NSObject {
        
        static let window: UIWindow = UIWindow()
        
        class func showWindow() {
            BS_TopWindow.window.frame = CGRect(x: 0, y: 0, width: screenWidth, height: 20)
           BS_TopWindow.window.windowLevel = UIWindowLevelAlert
           BS_TopWindow.window.backgroundColor = UIColor.clear
           BS_TopWindow.window.isHidden = false;
            
            let tap = UITapGestureRecognizer(target: self, action: #selector(windowClick))
            BS_TopWindow.window.addGestureRecognizer(tap)
        }
        
        @objc class private func windowClick() {
            
            let keyWindow = UIApplication.shared.keyWindow
            
         BS_TopWindow.searchScroolViewInView(keyWindow ?? UIWindow())
            
        }
        
        public class func searchScroolViewInView(_ superView: UIView) {
            
            for subView in superView.subviews {
                
//                if subView.isKind(of: UIScrollView.self) && subView.isShowingOnKeyWindow() {
//                    let view = subView as! UIScrollView
//                    var offset = view.contentOffset
//                    offset = CGPoint(x: offset.x, y: -(view.contentInset.top))
//                    view.setContentOffset(offset, animated: true)
//                }
                
                // 继续查找子控件
               BS_TopWindow.searchScroolViewInView(subView)
            }
            
        }
        
        
        
}
